﻿using System;
using Microsoft.Office.Interop.Excel;

namespace HYCodeBase.ExcelUtility.ModelLayer
{
	public class Workbook
	{
		public string Path
		{
			get
			{
				object property = ExcelUtilityMethod.GetProperty(this.m_workBook, "Path");
				if (property is string)
				{
					return (string)property;
				}
				return string.Empty;
			}
		}

		internal Workbook(object thisObject)
		{
			this.m_workBook = thisObject;
		}

		public Worksheets Worksheets
		{
			get
			{
				return new Worksheets(ExcelUtilityMethod.GetProperty(this.m_workBook, "Worksheets"));
			}
		}

		public void Save()
		{
			ExcelUtilityMethod.UseMethod(this.m_workBook, "Save", null);
		}

		public void SaveAs(string strpath)
		{
			ExcelUtilityMethod.UseMethod(this.m_workBook, "SaveAs", new object[]
			{
				strpath
			});
		}

		public Chart AddChart()
		{
			XlChartType xlChartType = XlChartType.xlColumnClustered;
			XlChartLocation xlChartLocation = XlChartLocation.xlLocationAutomatic;
			object obj = ExcelUtilityMethod.UseMethod(ExcelUtilityMethod.GetProperty(this.m_workBook, "Charts"), "Add", new object[]
			{
				Type.Missing,
				Type.Missing,
				1
			});
			ExcelUtilityMethod.SetProperty(obj, "ChartType", new object[]
			{
				xlChartType
			});
			ExcelUtilityMethod.UseMethod(obj, "Location", new object[]
			{
				xlChartLocation
			});
			return new Chart(obj);
		}

		public string FullName()
		{
			object obj = ExcelUtilityMethod.UseMethod(this.m_workBook, "FullName", null);
			if (obj is string)
			{
				return (string)obj;
			}
			return string.Empty;
		}

		public void Close()
		{
			ExcelUtilityMethod.UseMethod(this.m_workBook, "Close", new object[3]);
		}

		private object m_workBook;
	}
}
